package com.zms.parallel;

public class MyTaskRunner implements Runnable {

    public boolean[] flags;
    public int index;
    public int from,to;
    private MyTask task;
    private boolean debug;

    public MyTaskRunner(MyTask task,boolean debug) {
        this.task=task;
        this.debug=debug;
    }
    public MyTaskRunner(MyTask task) {
        this(task,false);
    }
    private void run_() {
        if(debug) {
            System.out.printf("From %d to %d\n",from,to);
        }
        for(int i=from;i<to;i++) {
            task.run(i);
        }
    }
    public void run() {
        try {
            run_();
        } finally {
            if(flags!=null) {
                flags[index]=true;
            }
        }
    }
}
